home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / screen32.lha / screen-3.2b / screen.h < prev    next >
C/C++ Source or Header  |  1992-06-12  |  12KB  |  567 lines

  1. /* Copyright (c) 1991
  2.  *      Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
  3.  *      Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
  4.  * Copyright (c) 1987 Oliver Laumann
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 1, or (at your option)
  9.  * any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program (see the file COPYING); if not, write to the
  18.  * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  *
  20.  * Noteworthy contributors to screen's design and implementation:
  21.  *    Wayne Davison (davison@borland.com)
  22.  *    Patrick Wolfe (pat@kai.com, kailand!pat)
  23.  *    Bart Schaefer (schaefer@cse.ogi.edu)
  24.  *    Nathan Glasser (nathan@brokaw.lcs.mit.edu)
  25.  *    Larry W. Virden (lwv27%cas.BITNET@CUNYVM.CUNY.Edu)
  26.  *    Howard Chu (hyc@hanauma.jpl.nasa.gov)
  27.  *    Tim MacKenzie (tym@dibbler.cs.monash.edu.au)
  28.  *    Markku Jarvinen (mta@{cc,cs,ee}.tut.fi)
  29.  *    Marc Boucher (marc@CAM.ORG)
  30.  *
  31.  ****************************************************************
  32.  * $Id: screen.h,v 1.4 92/02/04 21:38:19 jnweiger Exp $ FAU
  33.  */
  34.  
  35. /* screen.h now includes enough to satisfy its own references.
  36.  * only config.h is still needed.
  37.  */
  38.  
  39. #include <stdio.h>
  40. #include <errno.h>
  41.  
  42. #ifdef ISC
  43. # ifdef ENAMETOOLONG
  44. #  undef ENAMETOOLONG
  45. # endif
  46. # ifdef ENOTEMPTY
  47. #  undef ENOTEMPTY
  48. # endif
  49. # include <net/errno.h>
  50. #endif
  51.  
  52. #if defined(pyr)
  53. extern int errno;
  54. #endif
  55.  
  56. #ifdef sun
  57. # define getpgrp __getpgrp
  58. # define exit __exit
  59. #endif
  60.  
  61. #ifdef POSIX
  62. #include <unistd.h>
  63. # if defined(__STDC__)
  64. #  include <stdlib.h>
  65. # endif
  66. #endif
  67.  
  68. #ifdef sun
  69. # undef getpgrp
  70. # undef exit
  71. #endif
  72.  
  73. #ifdef POSIX
  74. # include <termios.h>
  75. # ifdef hpux
  76. #  include <bsdtty.h>
  77. # endif
  78. #else
  79. # ifdef TERMIO
  80. #  include <termio.h>
  81. # else
  82. #  include <sgtty.h>
  83. # endif /* TERMIO */
  84. #endif /* POSIX */
  85.  
  86. #if defined(BSD) || defined(sequent) || defined(pyr)
  87. # include <strings.h>
  88. #else /* BSD */
  89. # ifdef SVR4
  90. #  define strlen ___strlen___
  91. #  include <string.h>
  92. #  undef strlen
  93.    extern size_t strlen(const char *);
  94. # else /* SVR4 */
  95. #  include <string.h>
  96. # endif /* SVR4 */
  97. #endif /* BSD */
  98.  
  99. #if (defined(TIOCGWINSZ) || defined(TIOCSWINSZ)) && defined(M_UNIX)
  100. # include <sys/stream.h>
  101. # include <sys/ptem.h>
  102. #endif
  103.  
  104. #ifdef SUIDROOT
  105. #  ifdef LOCKPTY
  106. #     undef LOCKPTY
  107. #  endif
  108. #endif
  109.  
  110. #ifndef UTMPOK
  111. #  ifdef USRLIMIT
  112. #     undef USRLIMIT
  113. #  endif
  114. #endif
  115.  
  116. #ifndef LOGINDEFAULT
  117. #  define LOGINDEFAULT 0
  118. #endif
  119.  
  120. #ifndef F_OK
  121. #define F_OK 0
  122. #endif
  123. #ifndef X_OK
  124. #define X_OK 1
  125. #endif
  126. #ifndef W_OK
  127. #define W_OK 2
  128. #endif
  129. #ifndef R_OK
  130. #define R_OK 4
  131. #endif
  132.  
  133. #ifndef MAXPATH
  134. # define MAXPATH 1024
  135. #endif
  136.  
  137. #ifndef SIG_T_DEFINED
  138. # ifdef SIGVOID
  139. #  if defined(ultrix)
  140. #   define sig_t void
  141. #  else /* nice compilers: */
  142.     typedef void sig_t;
  143. #  endif
  144. # else
  145.    typedef int sig_t; /* (* sig_t) */
  146. # endif
  147. #endif /* SIG_T_DEFINED */
  148.  
  149. #if defined(SVR4) || (defined(SYSV) && defined(ISC))
  150. # define SIGPROTOARG   (int)
  151. # define SIGDEFARG     int sigsig
  152. # define SIGARG        0
  153. #else
  154. # define SIGPROTOARG   (void)
  155. # define SIGDEFARG
  156. # define SIGARG
  157. #endif
  158.  
  159. #if (!defined(SYSV) && !defined(POSIX) && !defined(apollo)) || defined(sysV68) 
  160. # ifndef PID_T_DEFINED
  161. typedef int pid_t;
  162. # endif /* PID_T_DEFINED */
  163. #endif
  164.  
  165. #if defined(M_XENIX)
  166. typedef int pid_t;
  167. typedef int gid_t;
  168. typedef int uid_t;
  169. #endif
  170.  
  171. #if defined(UTMPOK) && defined(_SEQUENT_)
  172. # define GETUTENT
  173. #endif
  174.  
  175. #ifdef GETUTENT
  176.   typedef char *slot_t;
  177. #else
  178.   typedef int slot_t;
  179. #endif
  180.  
  181. #if !defined(BSD) && !defined(sequent) && !defined(NeXT)
  182. # define index strchr
  183. # define rindex strrchr
  184. #endif
  185.  
  186. #ifdef SYSV /* jw. */
  187. # define bzero(poi,len) memset(poi,0,len)
  188. # define killpg(pgrp,sig) kill( -(pgrp), sig)
  189. #endif
  190.  
  191. #if defined(_POSIX_SOURCE) && defined(ISC)
  192. # ifndef O_NDELAY
  193. #  define O_NDELAY O_NONBLOCK
  194. # endif
  195. #endif
  196.  
  197. /* here comes my own Free: jw. */
  198. #define Free(a) {if ((a) == 0) abort(); else free((void *)(a)); (a)=0;}
  199.  
  200. #define Ctrl(c) ((c)&037)
  201.  
  202. /* modes for markroutine 
  203.  */
  204. #define PLAIN 0
  205. #define TRICKY 1
  206. #define CRAZY 2 /* should rather be TAXY or MAHEM though... */
  207.  
  208. /*typedef long off_t; */    /* Someone might need this */
  209.  
  210. enum state_t 
  211. {
  212.   LIT,                /* Literal input */
  213.   ESC,                /* Start of escape sequence */
  214.   ASTR,                /* Start of control string */
  215.   STRESC,            /* ESC seen in control string */
  216.   CSI,                /* Reading arguments in "CSI Pn ; Pn ; ... ; XXX" */
  217.   PRIN,                /* Printer mode */
  218.   PRINESC,            /* ESC seen in printer mode */
  219.   PRINCSI,            /* CSI seen in printer mode */
  220.   PRIN4            /* CSI 4 seen in printer mode */
  221. };
  222.  
  223. enum string_t 
  224. {
  225.   NONE,
  226.   DCS,                /* Device control string */
  227.   OSC,                /* Operating system command */
  228.   APC,                /* Application program command */
  229.   PM,                /* Privacy message */
  230.   AKA                /* a.k.a. for current screen */
  231. };
  232.  
  233. #define MAXSTR        256
  234. #define MAXARGS     64
  235. #define MSGWAIT     5
  236. #define MSGMINWAIT     1
  237.  
  238. /* 
  239.  * 4 <= IOSIZE <=1000
  240.  * you may try to vary this value. Use low values if your (VMS) system
  241.  * tends to choke when pasting. Use high values if you want to test
  242.  * how many characters your pty's can buffer.
  243.  */
  244. #define IOSIZE        80
  245.  
  246. /*
  247.  * if a nasty user really wants to try a history of 2000 lines on all 10
  248.  * windows, he will allocate 5 MegaBytes of memory, which is quite enough.
  249.  */
  250. #define MAXHISTHEIGHT 3000
  251. #define DEFAULTHISTHEIGHT 100
  252.  
  253. struct win 
  254. {
  255.   int wpid; /* process, that is connected to the other end of ptyfd */
  256.   int ptyfd;    /* usually the master side of our pty pair */
  257.   int ttyflag;    /* 1 if ptyfd is connected to a user specified tty. */
  258.   int aflag;
  259.   char outbuf[IOSIZE];
  260.   int outlen;
  261.   int autoaka, akapos;
  262.   char cmd[MAXSTR];
  263.   char tty[MAXSTR];
  264.   int args[MAXARGS];
  265.   int NumArgs;
  266.   slot_t slot;
  267.   char **image;
  268.   char **attr;
  269.   char **font;
  270.   int LocalCharset;
  271.   int charsets[4];
  272.   int ss;
  273.   int active;
  274.   int x, y;
  275.   char LocalAttr;
  276.   int saved;
  277.   int Saved_x, Saved_y;
  278.   char SavedLocalAttr;
  279.   int SavedLocalCharset;
  280.   int SavedCharsets[4];
  281.   int top, bot;
  282.   int wrap;
  283.   int origin;
  284.   int insert;
  285.   int keypad;
  286.   int width, height;    /* width AND height, as we have now resized wins. jw.*/
  287.   int histheight;       /* all histbases are malloced with width * histheight */
  288.   int histidx;          /* 0= < histidx < histheight; where we insert lines */
  289.   char **ihist;     /* the history buffer  image */
  290.   char **ahist;     /* attributes */
  291.   char **fhist;     /* fonts */
  292.   enum state_t state;
  293.   enum string_t StringType;
  294.   char string[MAXSTR];
  295.   char *stringp;
  296.   char *tabs;
  297.   int vbwait;            
  298.   int bell;
  299.   int flow;
  300.   int WinLink;
  301.   FILE *logfp;
  302.   int monitor;
  303.   int cursor_invisible;
  304.   int norefresh;    /* we dont redisplay when switching to that win */
  305. };
  306.  
  307. /*
  308.  * Definitions for flow
  309.  *   000  -(-)
  310.  *   001  +(-)
  311.  *   010  -(+)
  312.  *   011  +(+)
  313.  *   100  -(a)
  314.  *   111  +(a)
  315.  */
  316. #define FLOW_NOW    (1<<0)
  317. #define FLOW_AUTO    (1<<1)
  318. #define FLOW_AUTOFLAG    (1<<2)
  319.  
  320. /*
  321.  * Parameters for the Detach() routine
  322.  */
  323. #define D_DETACH    0
  324. #define D_STOP        1
  325. #define D_REMOTE    2
  326. #define D_POWER     3
  327. #define D_REMOTE_POWER    4
  328. #define D_LOCK        5
  329.  
  330. /*
  331.  * Here are the messages the attacher sends to the backend
  332.  */
  333. #define MSG_CREATE    0
  334. #define MSG_ERROR    1
  335. #define MSG_ATTACH    2
  336. #define MSG_CONT    3
  337. #define MSG_DETACH    4
  338. #define MSG_POW_DETACH    5
  339. #define MSG_WINCH    6
  340. #define MSG_HANGUP    7
  341.  
  342. struct msg
  343. {
  344.   int type;
  345.   union
  346.     {
  347.       struct
  348.     {
  349.       int lflag;
  350.       int aflag;
  351.       int flowflag;
  352.       int hheight;  /* size of scrollback buffer */
  353.       int nargs;
  354.       char line[MAXPATH];
  355.       char dir[MAXPATH];
  356.       char screenterm[20]; /* is screen really "screen" ? */
  357.     }
  358.       create;
  359.       struct
  360.     {
  361.       int apid;
  362.       int adaptflag; /* do we wish to adapt window size? */
  363.       int lines, columns;
  364.       char tty[MAXPATH];
  365.       char password[20];
  366.       char envterm[MAXPATH];
  367.     }
  368.       attach;
  369.       struct 
  370.     {
  371.       char password[20];
  372.       int dpid;
  373.       char tty[MAXPATH];
  374.     }
  375.       detach;
  376.       char message[MAXPATH * 2];
  377.     } m;
  378. };
  379.  
  380. /*
  381.  * And the signals the attacher receives from the backend
  382.  */
  383. #define SIG_BYE        SIGHUP
  384. #define SIG_POWER_BYE    SIGUSR1
  385. #define SIG_LOCK    SIGUSR2
  386. #define SIG_STOP    SIGTSTP
  387. #define SIG_PW_OK    SIGUSR1
  388. #define SIG_PW_FAIL    SIG_BYE
  389.  
  390.  
  391. struct mode
  392. {
  393. #ifdef POSIX
  394.   struct termios tio;
  395. # ifdef hpux
  396.   struct ltchars m_ltchars;
  397. # endif
  398. #else
  399. # ifdef TERMIO
  400.   struct termio tio;
  401. # else
  402.   struct sgttyb m_ttyb;
  403.   struct tchars m_tchars;
  404.   struct ltchars m_ltchars;
  405.   int m_ldisc;
  406.   int m_lmode;
  407. # endif                /* TERMIO */
  408. #endif                /* POSIX */
  409. };
  410.  
  411. #define BELL        7
  412. #define VBELLWAIT    1 /* No. of seconds a vbell will be displayed */
  413.  
  414. #define BELL_OFF    0 /* No bell has occurred in the window */
  415. #define BELL_ON     1 /* A bell has occurred, but user not yet notified */
  416. #define BELL_DONE    2 /* A bell has occured, user has been notified */
  417. #define BELL_VISUAL     3 /* A bell has occured in fore win, notify him visually */
  418.  
  419. #define MON_OFF     0 /* Monitoring is off in the window */
  420. #define MON_ON        1 /* No activity has occurred in the window */
  421. #define MON_FOUND    2 /* Activity has occured, but user not yet notified */
  422. #define MON_DONE    3 /* Activity has occured, user has been notified */
  423.  
  424. #define DUMP_TERMCAP    0 /* WriteFile() options */
  425. #define DUMP_HARDCOPY    1
  426. #define DUMP_EXCHANGE    2
  427.  
  428. #undef MAXWIN20
  429.  
  430. #ifdef MAXWIN20
  431. #define MAXWIN    20
  432. #else
  433. #define MAXWIN    10
  434. #endif
  435.  
  436. /* the key definitions are used in screen.c and help.c */
  437. /* keep this list synchronus with the names given in fileio.c */
  438. enum keytype
  439. {
  440.   KEY_IGNORE, /* Keep these first 2 at the start */
  441.   KEY_SCREEN,
  442.   KEY_0,  KEY_1,  KEY_2,  KEY_3,  KEY_4,
  443.   KEY_5,  KEY_6,  KEY_7,  KEY_8,  KEY_9,
  444. #ifdef MAXWIN20
  445.   KEY_10, KEY_11, KEY_12, KEY_13, KEY_14,
  446.   KEY_15, KEY_16, KEY_17, KEY_18, KEY_19,
  447. #endif
  448.   KEY_AKA,
  449.   KEY_CLEAR,
  450.   KEY_COLON,
  451.   KEY_COPY,
  452.   KEY_DETACH,
  453.   KEY_FLOW,
  454.   KEY_HARDCOPY,
  455.   KEY_HELP,
  456.   KEY_HISTNEXT,
  457.   KEY_HISTORY,
  458.   KEY_INFO,
  459.   KEY_KILL,
  460.   KEY_LASTMSG,
  461.   KEY_LICENSE,
  462.   KEY_LOCK,
  463.   KEY_LOGTOGGLE,
  464.   KEY_LOGIN,
  465.   KEY_MONITOR,
  466.   KEY_NEXT,
  467.   KEY_OTHER,
  468.   KEY_PASTE,
  469.   KEY_POW_DETACH,
  470.   KEY_PREV,
  471.   KEY_QUIT,
  472.   KEY_READ_BUFFER,
  473.   KEY_REDISPLAY,
  474.   KEY_REMOVE_BUFFERS,
  475.   KEY_RESET,
  476.   KEY_SET,
  477.   KEY_SHELL,
  478.   KEY_SUSPEND,
  479.   KEY_TERMCAP,
  480.   KEY_TIME,
  481.   KEY_VBELL,
  482.   KEY_VERSION,
  483.   KEY_WIDTH,
  484.   KEY_WINDOWS,
  485.   KEY_WRAP,
  486.   KEY_WRITE_BUFFER,
  487.   KEY_XOFF,
  488.   KEY_XON,
  489.   KEY_EXTEND,
  490.   KEY_X_WINDOWS,
  491.   KEY_BONUSWINDOW,
  492.   KEY_CREATE,
  493. };
  494.  
  495. struct key 
  496. {
  497.   enum keytype type;
  498.   char **args;
  499. };
  500.  
  501. #ifdef NETHACK
  502. #    define Msg_nomem Msg(0, "You feel stupid.")
  503. #else
  504. #    define Msg_nomem Msg(0, "Out of memory.")
  505. #endif
  506.  
  507. #ifdef DEBUG
  508. #    define debug(x) {fprintf(dfp,x);fflush(dfp);}
  509. #    define debug1(x,a) {fprintf(dfp,x,a);fflush(dfp);}
  510. #    define debug2(x,a,b) {fprintf(dfp,x,a,b);fflush(dfp);}
  511. #    define debug3(x,a,b,c) {fprintf(dfp,x,a,b,c);fflush(dfp);}
  512.     extern FILE *dfp;
  513. #else
  514. #    define debug(x) {}
  515. #    define debug1(x,a) {}
  516. #    define debug2(x,a,b) {}
  517. #    define debug3(x,a,b,c) {}
  518. #endif
  519.  
  520. #if defined(__STDC__)
  521. # ifndef __P
  522. #  define __P(a) a
  523. # endif
  524. #else
  525. # ifndef __P
  526. #  define __P(a) ()
  527. # endif
  528. # define const
  529. #endif
  530.  
  531. #ifdef hpux
  532. # define setreuid(ruid, euid) setresuid(ruid, euid, -1)
  533. # define setregid(rgid, egid) setresgid(rgid, egid, -1)
  534. #endif
  535.  
  536. #ifdef UTMPOK
  537. # ifdef SVR4
  538. #  include <utmpx.h>
  539. #  define UTMPFILE     UTMPX_FILE
  540. #  define utmp         utmpx
  541. #  define getutent     getutxent
  542. #  define getutid      getutxid
  543. #  define getutline    getutxline
  544. #  define pututline    pututxline
  545. #  define setutent     setutxent
  546. #  define endutent     endutxent
  547. # else /* SVR4 */
  548. #  include <utmp.h>
  549. # endif /* SVR4 */
  550. #endif
  551.  
  552. #ifndef UTMPFILE
  553. # ifdef UTMP_FILE
  554. #  define UTMPFILE     UTMP_FILE
  555. # else
  556. #  ifdef BSDI
  557. #   define UTMPFILE    "/var/run/utmp"
  558. #  else
  559. #   define UTMPFILE     "/etc/utmp"
  560. #  endif /* BSDI */
  561. # endif
  562. #endif
  563.  
  564. #if (!defined(SYSV) || defined(sun) || defined(RENO) || defined(xelos)) && !defined(_AIX)
  565. # define BSDWAIT
  566. #endif
  567.